package cn.stylefeng.guns.modular.system.service.impl;

import cn.stylefeng.guns.modular.system.dao.AppCashOutMapper;
import cn.stylefeng.guns.modular.system.dao.AppUserInfoMapper;
import cn.stylefeng.guns.modular.system.dao.ProxyUserMapper;
import cn.stylefeng.guns.modular.system.entity.AppUserInfo;
import cn.stylefeng.guns.modular.system.entity.CashOut;
import cn.stylefeng.guns.modular.system.service.AppCashOutService;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @ClassName AppCashOutServiceImpl
 * @Author lzy
 * @Date 2020/2/7 17:19
 * @VERSION 1.0
 **/
@Service
public class AppCashOutServiceImpl extends ServiceImpl<AppCashOutMapper, CashOut> implements AppCashOutService {
    @Autowired
    private AppUserInfoMapper appUserInfoMapper;

    @Autowired
    private ProxyUserMapper proxyUserMapper;

    @Override
    public List<Map<Object, Object>> findList(String startTime, String endTime, Integer withdrawId, Integer status, List<String> userIds) {
        return baseMapper.findList(startTime, endTime, withdrawId, status, userIds);
    }

    @Override
    public CashOut findOne(Integer orderId) {
        return baseMapper.findOne(orderId);
    }

    @Override
    @Transactional
    public void turnDown(CashOut cashOut, AppUserInfo userInfo) {
        //回滚操作一起执行
        try {
            baseMapper.updateById(cashOut);
            appUserInfoMapper.updateById(userInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    @Transactional
    public void withdrawal(User user, CashOut cashOut) {
        //回滚操作一起执行
        try {
            baseMapper.updateById(cashOut);
            proxyUserMapper.updateById(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
